﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Physio10Context;

namespace Physio_Clinic
{
    public partial class Report : System.Web.UI.Page
    {
        InvoiceDataSer dataSet = new InvoiceDataSer();
        InvoiceReport invr = new InvoiceReport();

        protected void Page_Load(object sender, EventArgs e)
        {
            Drugorder order = (Drugorder)Session["DrugOrder"];
            Booking booking = (Booking)Session["Booking"];

            string user = "";

            if (booking.Qf8soUser != null)
            {
                user = booking.Qf8soUser.Name;
            }
            else
            {
                user = "จ่ายสด";
            }

            dataSet.Invoice.AddInvoiceRow(user, order.GetOrderNumber(),
                DateTime.Today.ToShortDateString(),
                order.DateDefineProduct,
                (decimal)order.ReEvalTotalPrice(),
                order.Discount,
                order.Vat,
                order.PriceAfterDiscount,
                order.AllTotalPrice,
                order.GetTaxNumber());

            foreach (Drugorderdetail item in order.DrugDetailList)
            {
                dataSet.InvoiceDetail.AddInvoiceDetailRow(item.Drug.DrugCode, item.Drug.DrugName.ToString(),
                    (decimal)item.Drug.DrugPrice,
                    (int)item.Amount,
                    item.Price,
                    item.Discount,
                    item.Price);
            }

            invr.SetDataSource(dataSet);
            this.CrystalReportViewer1.ReportSource = invr;
            
        }
    }
}